<template>
  <el-dialog :title="title" :visible.sync="dialogVisible" width="600px" append-to-body>
    <el-form ref="form" :model="model" :rules="rules" label-width="80px" label-suffix=":">
          <div style="margin-bottom: 12px;">确定要<span style="color: red">{{ title }}</span>吗？采购单为：{{ params.purchase_number }}</div>
          <el-form-item label="审核说明" prop="check_remark">
              <el-input v-model.trim="model.check_remark" type="textarea" :rows="6" placeholder="请填写您要备注的内容（最多200字符）" :maxlength="200" show-word-limit clearable style="width: 100%"></el-input>
          </el-form-item>
          
      </el-form>
      
      <div slot="footer" class="dialo2-footer">
       <el-button type="primary" :loading="save" :disabled="save" @click="submit">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
      </div>
  </el-dialog>
</template>

<script>
import { pass_reject, pass_check } from '@/api/purchase'
export default {
  name: 'AuditDialog',
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    params: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
      return {
        model: {
          check_remark:'',
        },
        rules: {},
          save: false,
          loading: false
      }
  },
  computed: {
      title() {
          return this.params.type == 'pass'? `通过审核` : `驳回审核`
      },
      dialogVisible: {
          get() {
              return this.value
          },
          set(val) {
              this.$emit('input', val)
          },
      },
  },
  watch: { },
   mounted() { 
    
   },
  methods: {

      submit() {
         if(this.model.check_remark.length == 0) {
          return this.$message.error('请填写备注')
         }
         this.save = true
          const params = {...this.model, purchase_number: this.params.purchase_number}
         const request = this.params.type == 'pass' ? pass_check : pass_reject
         request(params).then((res)=>{
            this.$message.success(res.smg)
            this.$emit('success',true)
            this.cancel()
          }).finally(()=>{
            this.save = false
          })
              
      },
      cancel() {
          this.dialogVisible = false
      },
  },
}
</script>

<style>
.color-list {
  display: flex;
  align-items: center;
  height: 36px;
}
.color-item {
  width: 20px;
  height: 20px;
  margin-right: 10px;
  cursor: pointer;
  border: 2px solid #fff;
}
</style>
